home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWColor.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  6.0 KB  |  210 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWColor.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWCOLOR_H
  11. #define FWCOLOR_H
  12.  
  13. #ifndef SLCOLOR_H
  14. #include "SLColor.h"
  15. #endif
  16.  
  17. // ----- Foundation Includes -----
  18.  
  19. #ifndef FWSTDDEF_H
  20. #include <FWStdDef.h>
  21. #endif
  22.  
  23. // ----- Macintosh Includes -----
  24.  
  25. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  26. #include <QuickDraw.h>
  27. #endif
  28.  
  29. // ----- Windows Includes -----
  30.  
  31. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  32. #include <windows.h>
  33. #endif
  34.  
  35. //========================================================================================
  36. //    Forward Class Declarations
  37. //========================================================================================
  38.  
  39. class FW_CColor;
  40. class FW_CWritableStream;
  41. class FW_CReadableStream;
  42.  
  43. //========================================================================================
  44. //    Globale operators << and >>
  45. //========================================================================================
  46.  
  47. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CColor& color);
  48. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CColor& color);
  49.  
  50. //========================================================================================
  51. //    class FW_CColor
  52. //========================================================================================
  53.  
  54. class FW_CColor : public FW_SColor
  55. {
  56. //----------------------------------------------------------------------------------------
  57. //    Constructors/Destructors
  58. //
  59. public:
  60.     FW_CColor();
  61.     FW_CColor(const FW_CColor& color);
  62.     FW_CColor(FW_RGBComponent r, FW_RGBComponent g, FW_RGBComponent b);
  63.     FW_CColor(FW_CReadableStream& stream);
  64.     FW_CColor(FW_SColor sColor);
  65.     
  66.     // calls Blend, described below
  67.     FW_CColor(const FW_CColor& colorFrom, const FW_CColor& colorTo, unsigned short numer, unsigned short denom);
  68.  
  69. #ifdef FW_BUILD_MAC
  70.     FW_CColor(const RGBColor* rgbPtr);
  71.     FW_CColor(const RGBColor& rgb);
  72. #endif
  73.  
  74. #ifdef FW_BUILD_WIN
  75.     FW_CColor(COLORREF colorref);
  76. #endif
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    Operators
  80. //
  81. public:
  82. #ifdef FW_BUILD_MAC    
  83.     FW_Boolean operator==(const RGBColor& rgb) const;
  84.     FW_Boolean operator!=(const RGBColor& rgb) const;
  85. #endif
  86.  
  87.     // ----- Assignment operator -----    
  88.     FW_CColor& operator=(const FW_CColor& color);
  89.     FW_CColor& operator=(FW_SColor sColor);
  90.     
  91. #ifdef FW_BUILD_MAC
  92.     FW_CColor& operator=(const RGBColor& rgb);
  93.     operator RGBColor() const;
  94. #endif
  95.     
  96. #ifdef FW_BUILD_WIN
  97.     FW_CColor& operator=(RGBQUAD quad);
  98.     operator RGBQUAD() const;
  99.  
  100.     FW_CColor& operator=(RGBTRIPLE triple);
  101.     operator RGBTRIPLE() const;
  102.     
  103.     FW_CColor& operator=(COLORREF colorref);
  104.     operator COLORREF() const;
  105. #endif
  106.  
  107.     // ----- Arithmetic, by another color -----
  108.     FW_CColor operator+(const FW_CColor& color) const;
  109.     FW_CColor operator-(const FW_CColor& color) const;
  110.  
  111.     FW_CColor& operator+=(const FW_CColor& color);
  112.     FW_CColor& operator-=(const FW_CColor& color);
  113.  
  114.     // ----- Arithmetic by a scalar -----
  115.  
  116.     FW_CColor operator+(unsigned short a) const;
  117.     FW_CColor operator-(unsigned short a) const;
  118.     FW_CColor operator*(unsigned short a) const;
  119.     FW_CColor operator/(unsigned short a) const;
  120.  
  121.     FW_CColor& operator+=(unsigned short a);
  122.     FW_CColor& operator-=(unsigned short a);
  123.     FW_CColor& operator*=(unsigned short a);
  124.     FW_CColor& operator/=(unsigned short a);
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    New public API
  128. //
  129. public:
  130.     // ----- Set/Get RGB Component -----
  131.     void        SetRGB(FW_RGBComponent r, FW_RGBComponent g, FW_RGBComponent b);
  132.     
  133.     // value is returned as unsigned short even though only lower 8 bits are significant
  134.     // this is to facilitate arithmetic on the returned components.
  135.     void        GetRGB(unsigned short& r, unsigned short& g, unsigned short& b) const;
  136.     
  137.     FW_Boolean     IsDarkerThan(const FW_CColor& color) const;
  138.     FW_Boolean     IsLighterThan(const FW_CColor& color) const;
  139.  
  140.     // ----- Set color to average of colorA and colorB
  141.     FW_CColor& Average(const FW_CColor& colorA, const FW_CColor& colorB);
  142.  
  143.     // ----- Scale color proportionately from color 1 to color 2
  144.     FW_CColor& Blend(const FW_CColor& colorFrom, const FW_CColor& colorTo, unsigned short numer, unsigned short denom);
  145.  
  146.     unsigned long     Brightness() const;
  147.     
  148.     FW_RGBComponent Red() const;
  149.     FW_RGBComponent Green() const;
  150.     FW_RGBComponent Blue() const;
  151.     
  152.     // ----- Persistence -----
  153.     void        Read(FW_CReadableStream& stream);
  154.     void        Write(FW_CWritableStream& stream) const;
  155. };
  156.  
  157. //========================================================================================
  158. //    inlines
  159. //========================================================================================
  160.  
  161. inline FW_RGBComponent FW_CColor::Red() const
  162. {
  163.     return FW_PrivRGB_R(*this);
  164. }
  165.  
  166. inline FW_RGBComponent FW_CColor::Green() const
  167. {
  168.     return FW_PrivRGB_G(*this);
  169. }
  170.  
  171. inline FW_RGBComponent FW_CColor::Blue() const
  172. {
  173.     return FW_PrivRGB_B(*this);
  174. }
  175.  
  176. #ifdef FW_BUILD_MAC
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CColor::operator!=
  179. //----------------------------------------------------------------------------------------
  180. inline FW_Boolean FW_CColor::operator!=(const RGBColor& rgb) const
  181. {
  182.     return !(*this == rgb);
  183. }
  184. #endif
  185.  
  186. #ifdef FW_BUILD_WIN
  187. //----------------------------------------------------------------------------------------
  188. //    FW_CColor::operator=
  189. //----------------------------------------------------------------------------------------
  190.  
  191. inline FW_CColor& FW_CColor::operator=(COLORREF color)
  192. {
  193.     fRGB = color;
  194.     return *this;
  195. }
  196. #endif
  197.  
  198. #ifdef FW_BUILD_WIN
  199. //----------------------------------------------------------------------------------------
  200. //    FW_CColor::operator COLORREF
  201. //----------------------------------------------------------------------------------------
  202.  
  203. inline FW_CColor::operator COLORREF() const
  204. {
  205.     return fRGB;
  206. }
  207. #endif
  208.  
  209. #endif
  210.